home *** CD-ROM | disk | FTP | other *** search
Oberon Text | 1995-06-30 | 6.3 KB | 168 lines | [TEXT/.Ob4] |
- Syntax10.Scn.Fnt
- Syntax10i.Scn.Fnt
- StampElems
- Alloc
- 8 Nov 94
- Syntax10b.Scn.Fnt
- MODULE DialogKeplers; (* based on KeplerElems by J.Templ 27.09.93 *)
- (** Markus Knasm
- ller 31 Oct 94 -
- IMPORT DialogFrames, Dialogs, DialogTexts, Display, Files, In, KeplerGraphs, KeplerFrames, KeplerPorts, MenuViewers,
- Oberon, TextFrames, TextPrinter, Texts, Viewers;
- CONST
- MM = 1; ML = 0; MR = 2;
- menu = "System.Close System.Copy System.Grow DialogKeplers.Update ";
- dUnit = TextFrames.Unit; pUnit = TextPrinter.Unit;
- W* = 100; H* = 100;
- TYPE
- Item* = POINTER TO ItemDesc;
- ItemDesc* = RECORD(Dialogs.ObjectDesc)
- graph*: KeplerGraphs.Graph;
- dx, dy, grid: INTEGER;
- END;
- Frame = POINTER TO FrameDesc;
- FrameDesc = RECORD (KeplerFrames.FrameDesc)
- elem: Item
- END;
- PROCEDURE Max (x, y: INTEGER): INTEGER;
- BEGIN IF x > y THEN RETURN x ELSE RETURN y END
- END Max;
- PROCEDURE CopyGraph (g: KeplerGraphs.Graph): KeplerGraphs.Graph;
- VAR buf: Files.File; R: Files.Rider; o: KeplerGraphs.Object;
- BEGIN
- buf := Files.New ("");
- Files.Set (R, buf, 0); KeplerGraphs.Reset;
- KeplerGraphs.WriteObj (R, g);
- Files.Set (R, buf, 0); KeplerGraphs.Reset;
- KeplerGraphs.ReadObj (R, o);
- RETURN o(KeplerGraphs.Graph)
- END CopyGraph;
- PROCEDURE (g: Item) Draw* (x, y: INTEGER; f: Display.Frame);
- (** displays the object at (x, y) in frame f *)
- VAR x0, y0, w, h, mode, col: INTEGER; f1: KeplerFrames.Frame;
- BEGIN
- g.GetDim (x0, y0, w, h); col := f(DialogFrames.Frame).col;
- IF g.selected THEN mode := Display.invert ELSE mode := Display.replace END;
- IF (g.graph = NIL) OR (x < f.X) OR (y < f.Y) OR (x + w > f.X + f.W) OR (y + h > f.Y + f.H) THEN
- Display.ReplPatternC (f, Display.white, Display.grey1, x, y, w, h, 0, 0, mode)
- ELSE
- f1 := KeplerFrames.New (g.graph); f := f1;
- f1.X := x; f1.Y := y; f1.W := w; f1.H := h;
- f1.x0 := - g.dx; f1.y0 := - (f1.H * 4 + g.dy); f1.scale := 4;
- IF g.graph.cons # NIL THEN g.graph.Draw (f1) ELSE f1.DrawRect (0, 0, 99, 99, col, mode) END
- END
- END Draw;
- PROCEDURE (g: Item) Print* (x, y: INTEGER);
- (** prints the object at printer coordinates (x, y) *)
- VAR x0, y0, w, h: INTEGER; p: KeplerPorts.PrinterPort;
- BEGIN
- g.GetPDim (x0, y0, w, h);
- NEW (p);
- p.X := x; p.Y := y; p.W := 4 * w; p.H := 4 * h;
- p.x0 := - g.dx; p.y0 := - (p.H + g.dy); p.scale := 1;
- g.graph.Draw (p)
- END Print;
- PROCEDURE (g: Item) Copy* (VAR dup: Dialogs.Object);
- (** allocates dup and makes a deep copy of o. Before calling this methode dup should be equal NIL *)
- VAR x: Item;
- BEGIN
- IF dup = NIL THEN NEW (x); dup := x ELSE x := dup(Item) END;
- g.Copy^ (dup); x.graph := CopyGraph (g.graph); x.dx := g.dx; x.dy := g.dy; x.grid := g.grid
- END Copy;
- PROCEDURE (g: Item) Load* (VAR r: Files.Rider);
- (** reads the object from rider r *)
- VAR o: KeplerGraphs.Object;
- BEGIN
- g.Load^ (r); Files.ReadInt (r, g.dx); Files.ReadInt (r, g.dy);
- Files.ReadInt (r, g.grid);
- KeplerGraphs.Reset; KeplerGraphs.ReadObj (r, o); g.graph := o(KeplerGraphs.Graph)
- END Load;
- PROCEDURE (g: Item) Store* (VAR r: Files.Rider);
- (** writes the object to rider r *)
- BEGIN
- g.Store^ (r); Files.WriteInt (r, g.dx); Files.WriteInt (r, g.dy);
- Files.WriteInt (r, g.grid);
- KeplerGraphs.Reset; KeplerGraphs.WriteObj (r, g.graph)
- END Store;
- PROCEDURE (g: Item) Handle* (f: Display.Frame; VAR m: Display.FrameMsg);
- (** handles messages which were sent to frame f *)
- VAR t: Texts.Text;
- BEGIN
- g.Handle^ (f, m);
- WITH f: DialogFrames.Frame DO
- WITH m: Oberon.InputMsg DO
- IF (m.id = Oberon.track) & ((m.keys = {MM}) OR (m.keys = {MR}) OR (m.keys = {ML})) & (g.cmd[0] # 0X) THEN
- DialogTexts.GetParText (g.par, g.panel, t);
- g.CallCmd (f, Viewers.This (m.X, m.Y), t)
- END
- ELSE
- END
- ELSE
- END
- END Handle;
- PROCEDURE HandleFrame (f0: Display.Frame; VAR msg: Display.FrameMsg);
- VAR f: Frame;
- BEGIN
- WITH f0: Frame DO
- WITH msg: Oberon.CopyMsg DO
- NEW (f); msg.F := f; f^ := f0^
- ELSE KeplerFrames.Handle (f0, msg)
- END
- END
- END HandleFrame;
- PROCEDURE (g: Item) Edit* ();
- (** opens a graphic frame for editing the properties of the object *)
- VAR v: Viewers.Viewer; f: Frame; x, y: INTEGER;
- BEGIN
- NEW (f); f.G := CopyGraph (g.graph); f.G.notify := KeplerFrames.NotifyDisplay;
- f.handle := HandleFrame; f.grid := g.grid; f.scale := 4; f.x0 := 0; f.y0 := 0; f.elem := g;
- Oberon.AllocateSystemViewer (Oberon.Mouse.X, x, y);
- v := MenuViewers.New (TextFrames.NewMenu ("DialogKeplers.Graph", menu), f, TextFrames.menuH, x, y)
- END Edit;
- PROCEDURE (g: Item) Open;
- VAR b: KeplerPorts.BalloonPort; x, y, w, h: INTEGER;
- BEGIN
- NEW (b); KeplerPorts.InitBalloon (b);
- g.graph.Draw (b); (* get bounding box *)
- g.GetDim (x, y, w, h);
- g.dx := b.X; g.dy := b.Y; w := Max (w, b.W DIV 4); h := Max (h, b.H DIV 4);
- g.SetDim (x, y, w, h, g.overlapping)
- END Open;
- PROCEDURE Insert*;
- (** Insert (name | ^ ) inserts a graphic - item in the panel containing the caret position *)
- VAR w, h, x, y, xh, yh: INTEGER; g: Item; p: Dialogs.Panel; name: ARRAY 64 OF CHAR;
- graph: KeplerGraphs.Graph;
- BEGIN
- NEW (g);
- DialogFrames.GetCaretPosition (p, x, y);
- IF (p # NIL) THEN
- g.Init; In.Open; In.Name (name);
- IF ~In.Done THEN COPY ("", name); In.Open END;
- g.SetName (name);
- graph := KeplerGraphs.Old (name);
- IF graph = NIL THEN NEW (graph) END;
- g.graph := graph;
- In.Int (xh); In.Int (yh); In.Int (w); In.Int (h);
- IF In.Done THEN
- x := xh; y := yh
- ELSE
- w := W; h := H
- END;
- g.SetDim (x, y, w, h, FALSE);
- g.Open;
- p.Insert (g, FALSE)
- ELSE
- Dialogs.res := Dialogs.noPanelSelected
- END;
- IF Dialogs.res # 0 THEN Dialogs.Error ("DialogKeplers") END;
- END Insert;
- PROCEDURE Update*;
- VAR v: Viewers.Viewer; f: Frame; g: KeplerGraphs.Graph;
- BEGIN
- v := Oberon.Par.vwr; f := v.dsc.next(Frame);
- g := f.G; g.All (0); (* deselect *)
- f.elem.graph := CopyGraph (f.G); f.elem.grid := f.grid;
- f.elem.Open; f.elem.Restore; f.elem.panel.MarkMenu;
- END Update;
- END DialogKeplers.
-